package com.clsclassloder;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException,
            IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        MyClassLoader myClassLoader = new MyClassLoader("/test_workspace");
        Class<?> aClass = myClassLoader.loadClass("com.clsclassloder.Person");
        Object person = aClass.newInstance();
        Method method = aClass.getMethod("setName", String.class);
        Method method2 = aClass.getMethod("setAge", int.class);
        Method method3 = aClass.getMethod("toString");
        method.invoke(person, "zhangsan");
        method2.invoke(person, 22);
        System.out.println(method3.invoke(person));

        Class<?> aClass2 = myClassLoader.loadClass("com.clsclassloder.Person");
        IPerson person2 = (IPerson) aClass2.newInstance();
        person2.say("hello world");

        System.out.println("person2.getClass().getClassLoader() = " + person2.getClass().getClassLoader());
        
    }
}
